package com.code.google.wormon;

import java.awt.Graphics2D;
import java.awt.Image;

import com.code.google.wormon.base.Game;
import com.code.google.wormon.base.GameScene;

public class WormonScene implements GameScene {

	private Double hPos = 0.0d;
	private Double vPos = 0.0d;

	private Boolean autoRepeatH = false;
	private Boolean autoRepeatV = false;

	private Integer sceneWidth;
	private Integer sceneHeight;
	private Image image;

	private Game game;

	public WormonScene(Game game, Integer width, Integer height, Image image, Boolean autoRepeatH, Boolean autoRepeatV) {
		super();
		this.game = game;
		this.sceneWidth = width;
		this.sceneHeight = height;
		this.image = image;
		this.autoRepeatH = autoRepeatH;
		this.autoRepeatV = autoRepeatV;
	}

	@Override
	public void draw(Graphics2D g2d) {
		Integer positionH = (int) (sceneWidth * hPos);

		Integer imgX = image.getWidth(null) - (positionH % image.getWidth(null));

		g2d.drawImage(image, 0, 0, imgX, image.getHeight(null), image.getWidth(null) - imgX, 0, image.getWidth(null), image.getHeight(null), null);

		Integer total = imgX;
		do {
			g2d.drawImage(image, total, 0, total + image.getWidth(null), game.getScreenHeight(), 0, 0, image.getWidth(null), game.getScreenHeight(), null);
			total += image.getWidth(null);
		} while (total < game.getScreenWidth());

	}

	@Override
	public Integer getSceneHeight() {
		return sceneHeight;
	}

	@Override
	public Integer getSceneWidth() {
		return sceneWidth;
	}

	@Override
	public void setHPos(double hpos) {
		this.hPos = hpos;
	}

	@Override
	public void setVPos(double vpos) {
		this.vPos = vpos;
	}

	@Override
	public Boolean isAutoRepeatH() {
		return null;
	}

	@Override
	public Boolean isAutoRepeatV() {
		return null;
	}
}
